package com.dong.vdbtc.validation;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.validation.*;

import java.util.List;

/**
 * description
 *
 * @author Administrator 2021/09/07 19:37
 */
public class ValidationTest {

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

        User user = context.getBean(User.class);
        System.out.println(user);

        UserValidator userValidator = context.getBean(UserValidator.class);
        DataBinder dataBinder = new DataBinder(user);
        dataBinder.setValidator(userValidator);
        dataBinder.validate();
        BindingResult result = dataBinder.getBindingResult();
        List<ObjectError> list = result.getAllErrors();
        for(ObjectError error : list){
            System.out.println(error.getCode());
        }
    }
}
